package rock.negagame.client;

import rock.negagame.client.sprites.control.GameController;
import rock.negagame.client.sprites.control.Pantalla;
import static com.google.gwt.event.dom.client.KeyCodes.*;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;


/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class NegaGame implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	
	int i = 0;
	Pantalla p;
	
	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */


	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		Event.addNativePreviewHandler(new Event.NativePreviewHandler(){
			                        public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
			                                if (event.getTypeInt()==Event.ONKEYPRESS){			                                	
			                                	GameController.getGame().l.setText(""+event.getNativeEvent().getKeyCode());
			                                	switch(event.getNativeEvent().getKeyCode()){
				                                	case KEY_CTRL:	GameController.getGame().eventoDisparo();
				                                	GameController.getGame().l.setText("dispara ");
				                                	
				                                		break;
				                                	case 32: 
				                                	GameController.getGame().l.setText("dispara ");
				                                	GameController.getGame().eventoDisparo();
				                                		break;
				                                	default: 
				                                		break;
			                                	}			                                	
			                                }else 
			                        		if (event.getTypeInt()==Event.ONKEYUP){			                                	
			                        			int code = event.getNativeEvent().getKeyCode();
			                        			if(code == KEY_UP || code == KEY_DOWN||code == KEY_LEFT||code == KEY_RIGHT){
			                        			GameController.getGame().eventoPara(event.getNativeEvent().getKeyCode());
			                        			GameController.getGame().l.setText("para");
			                                	i=0;}
			                                }else if (event.getTypeInt()==Event.ONKEYDOWN){			                                			                                	
												int code = event.getNativeEvent().getKeyCode();
												if(code == KEY_UP || code == KEY_DOWN||code == KEY_LEFT||code == KEY_RIGHT){
			                                	GameController.getGame().eventoEmpieza(event.getNativeEvent().getKeyCode());
			                                	i++;
			                                	GameController.getGame().l.setText("empieza " + i);
			                                	}else if(code == KEY_SHIFT){
			                                		GameController.getGame().eventoDisparo();
			                                		GameController.getGame().l.setText("dispara " +i);
			                                	}
			                                	
			                                }
			                        }
			                 }); 
		
		GameController.getGame().start();
		RootPanel.get().add(Pantalla.getPantalla());
		RootPanel.get().add(GameController.getGame().l);
		
	}
}
